package com.wimcorp.magic.abilities;

import java.rmi.RemoteException;

import javax.persistence.Entity;
import javax.persistence.Table;
import javax.persistence.Transient;

import com.wimcorp.magic.abilities.trigger.AbilityTrigger;
import com.wimcorp.magic.cards.Creature;
import com.wimcorp.magic.cards.PlayingCard;
import com.wimcorp.magic.exception.CastException;
import com.wimcorp.magic.input.Target;

/**
 * example {target:'ANY',locations:['GRAVEYARD'],options :['CREATURE']
 * behaviors:}
 * 
 * target options : ANY,SELF,OPPONENT,THIS
 * 
 * types options : 'CREATURE'
 * 
 * location options : BATTLEFIELD,HAND,GRAVEYARD,EXILE,DECK
 * 
 * behaviors options :
 * 
 * duration : PERMANENT
 */
@Entity
@Table(name = "copycreature", schema = "abilities")
public class CopyCreature extends Ability {

	@Transient
	private Creature creature = null;

	protected CopyCreature() {
	}

	public CopyCreature(AbilityTrigger trigger) {
		super(trigger);
	}
	
	public CopyCreature(CopyCreature ability){
		super(ability);
	}
	

	@Override
	protected void executeAbility() throws CastException {
		creature = (Creature) getAbilityTarget();
		if (creature != null) {
			creature = (Creature) creature.copy();
			creature.setPlayer(getPlayer());
			creature.cast();
			getPlayer().getSummoningPlaines().playCard(creature);
			registerUndo();
		}
	}

	public void uncast() {
		creature.graveyard();
	}

	@Override
	public CopyCreature clone() {
		return new CopyCreature(this);
	}
	
	@Override
	public boolean isInputRequired(){
		if (Target.THIS.equals(getTarget())) {
			return false;
		}
		return true;
	}

}
